package com.open.capacity.study.controller;

import com.open.capacity.common.exception.controller.ControllerException;
import com.open.capacity.common.exception.service.ServiceException;
import com.open.capacity.common.model.LearnIter;
import com.open.capacity.common.web.PageResult;
import com.open.capacity.common.web.Result;
import com.open.capacity.log.annotation.LogAnnotation;
import com.open.capacity.study.service.LearnIterService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
@RequestMapping("/learnIter")
@Api(tags = "LEARN-ITER API")
public class LearnIterController {
    @Autowired
    private LearnIterService learnIterService;

    /**
     * 新增
     */
    @PostMapping("/insert")
    //权限注解（暂无）
    //@PreAuthorize("hasAnyAuthority('')")
    @ApiOperation(value = "添加用户学习进度迭代阶段")
    @LogAnnotation(module = "study-center", recordRequestParam = false)
    public Result insert(@RequestBody LearnIter learnIter) throws ControllerException {
        try {
            return learnIterService.insert(learnIter);
        }catch (ServiceException e){
            throw new ControllerException(e);
        }
    }

    /**
     * 查询
     */
    @PostMapping("/query")
    //权限注解（暂无）
    //@PreAuthorize("hasAnyAuthority('')")
    @ApiOperation(value = "查询用户学习进度迭代进度")
    @LogAnnotation(module = "study-center", recordRequestParam = false)
    public PageResult<LearnIter> query(@RequestParam Map<String,Object> params) throws ControllerException{
        try {
            return learnIterService.query(params);
        }catch (ServiceException e){
            throw new ControllerException(e);
        }
    }
}
